<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.css" rel="stylesheet">
  <style>
    .todo-container{
      max-width: 800px;
      margin: 20px auto;
      padding: 30px;
      border: 1px solid #555;
      border-radius: 10px;
    }
    .todo-list{
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="todo-container">
      <div class="todo-header row">
        <div class="col-md-10">
          <input type="text" class="form-control" v-model.trim="todoText">
        </div>
        <div class="col-md-2">
          <button @click="addTodo" class="btn btn-primary">新增</button>
        </div>
      </div>
      <div class="todo-list">
        <ul class="list-group">
          <li v-if="todos.length === 0" class="list-group-item text-center">暂无代办事项</li>
          <li 
            class="list-group-item"
            v-for="(todo,index) in todos"
            :key="index"
          >
            {{todo.content}}
          </li>
         
        </ul>
      </div>
    </div>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        todoText: '', // 绑定输入框内容
        todos: [
          
        ]
      },
      methods: {
        addTodo () {
          if(this.todoText === '') {
            return false;
          }
          // 新增待办事项
          this.todos.unshift({
            content: this.todoText,
            done: false
          })
          // 清空input
          this.todoText = '';
        }
      }
    })
  </script>
</body>
</html>